//import uView from "@/components/uview-ui/index.js";
	import {
		getTeamByUser,swTeam
	} from '@/api/index.js'

export const checkToken = () => {
	let token = uni.getStorageSync('token')
	if (!token) {
		//console.log('checkToken');
		uni.showModal({
			title: '温馨提示',
			content: '请您先完成登录,以免影响使用',
			cancelColor: '#333333',
			confirmColor: '#4DC0D9',
			customStyle: {
				content: 'color: #333333;' // 这里可以设置你想要的颜色
			},
			success: function(res) {
				if (res.confirm) {
					uni.redirectTo({
						url: '/pages/login/index'
					});
					return false
					// uni.navigateTo({
					// 	url: '/pages/login/index'
					// })
					//console.log('用户点击确定');
				} else if (res.cancel) {
					return false
					//console.log('用户点击取消');
				}
			}
		});
		// uni.showToast({
		// 	icon:"none",
		// 	title: '请先登录',
		// 	duration: 2000
		// })
		//$u.toast('请先登录')
		return false
	}
	//checkAuth()
	return true
	//console.log(token,111);
}

export const checkAuth = () => {
	let info = uni.getStorageSync('userinfo')
	if (info?.user?.nickName && info?.user?.nickName !== undefined) { //有号码说明登录过，不需要跳转到完善信息页面了
		return true
	} else {
		// console.log('checkAuth');
		uni.showModal({
			title: '温馨提示',
			content: '请您先完善个人信息,以免影响使用',
			cancelColor: '#333333',
			confirmColor: '#4DC0D9',
			customStyle: {
				content: 'color: #333333;' // 这里可以设置你想要的颜色
			},
			success: function(res) {
				if (res.confirm) {
					uni.navigateTo({
						url: '/pages/login/info'
					});
					return false
					// uni.navigateTo({
					// 	url: '/pages/login/index'
					// })
					//console.log('用户点击确定');
				} else if (res.cancel) {
					return false
					//console.log('用户点击取消');
				}
			}
		})
		return false
		//this.$u.route('/pages/index/index?to=0'); 
		//return
	}
}

export const chooseTeamNow = async()=>{
	let res = uni.getStorageSync('myTeam')
	if (res && res?.code == 200) {  //本地存储了团队
	}else{
		let obj = {
			'pageNum': 1,
			'pageSize': 15,
		}
		let res = await getTeamByUser(obj)
		if(res.code == 200&&res.total >0){
			let myTeamRes = await swTeam(res.rows[0].id)
			//console.log(res);
			if (myTeamRes.code == 200) {
				uni.setStorageSync('myTeam', myTeamRes)
			}
		}
	}
}


